//导入vuex
import Vuex from 'vuex';
//导入vue 
import Vue from 'vue';

//使用Vuex 
Vue.use(Vuex);
//导出Vuex
export default new Vuex.Store({
	state: {
		gTitle: {
			pic: "../../static/img/logo.png"
		},
		joks: [],
	},
	mutations: {
		setJoks(state, data) {
			state.joks = data;
		},
		Setpic(state, data) {
			state.gTitle.pic = data;
		}
	},
	actions: {
		//和后端交互，异步操作都会放在actions中
		getJok(context, data) {
			uni.request({
				url: "http://520mg.com/mi/list.php",
				method: 'get',
				data: data,
				//axios get 请求参数用params,post用data
				//uni.request post和get传参都用data
				//根据content-type,如果是application/json,那么data是json，如果是urlencoded data是url编码形式
				success: (res) => {
					console.log(res);
					context.commit('setJoks', res.data.result);
				}
			})
		}
	},
	//内部计算
	getters: {},
	modules: {},
})
